
using Gtk;
using System;

namespace GtkControls
{
    public class NotificationBar : EventBox
    {
        private HBox _hbox;
        private string _message;
        private Gtk.MessageType _type;

        public NotificationBar (Gtk.MessageType type, string message) : base ()
        {
            AppPaintable = true;
            _message = message;
            _type = type;
            
            Build();
        }
        
        private void Build()
        {
            _hbox = new HBox();
            Child = _hbox;
            
             AddImage(_type);
            AddText(_message);
            AddCloseButton();
            ShowAll();
        }
        
        private void AddImage(Gtk.MessageType type)
        {
            Gtk.Image image = null;
    
            switch (type) {
            case Gtk.MessageType.Error:
                image = new Gtk.Image (Gtk.Stock.DialogError, Gtk.IconSize.Button);
                break;
            case Gtk.MessageType.Question:
                image = new Gtk.Image (Gtk.Stock.DialogQuestion, Gtk.IconSize.Button);
                break;
            case Gtk.MessageType.Info:
                image = new Gtk.Image (Gtk.Stock.DialogInfo, Gtk.IconSize.Button);
                break;
            case Gtk.MessageType.Warning:
                image = new Gtk.Image (Gtk.Stock.DialogWarning, Gtk.IconSize.Button);
                break;
            }

            image.Show ();
            _hbox.PackStart(image, false, false, 10);
        }
        
        private void AddText(string message)
        {
            _hbox.PackStart(new Gtk.Label(message), false, false, 10);
        }

        private void AddCloseButton()
        {
            Gtk.Button button = new Gtk.Button();
            button.Label = "Close";
            button.Image = new Gtk.Image (Gtk.Stock.Close, Gtk.IconSize.Button);
            button.Clicked += delegate { this.Destroy(); };
            _hbox.PackEnd(button, false, false, 0);
        }

        protected override void OnStyleSet(Style style)
        {
            
            //ModifyBg(StateType.Normal, Style.Background(StateType.Selected));
        }

        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            ModifyBg(StateType.Normal, Style.Background(StateType.Selected));
            GdkWindow.DrawRectangle(Style.ForegroundGC(StateType.Active), false, 0, 0, Allocation.Width - 1, Allocation.Height - 1);
            return base.OnExposeEvent(evnt);
        }
    }
}
